package com.example.tabbar.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.Switch
import com.example.tabbar.databinding.FragmentSetParameterBinding

@SuppressLint("UseSwitchCompatOrMaterialCode")
class SetParameterFragment : Fragment() {
    private var binding: FragmentSetParameterBinding? = null
    private var tempValue: EditText? = null
    private var humidityValue: EditText? = null
    private var kpaValue: EditText? = null
    private var tempSwitch: Switch? = null
    private var humiditySwitch: Switch? = null
    private var kpaSwitch: Switch? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentSetParameterBinding.inflate(inflater, container, false)
        return binding!!.root
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        initView()
        tempSwitch?.setOnCheckedChangeListener { _, isChecked ->
            tempValue?.isEnabled = isChecked
        }

        humiditySwitch?.setOnCheckedChangeListener { _, isChecked ->
            humidityValue?.isEnabled = isChecked
        }

        kpaSwitch?.setOnCheckedChangeListener { _, isChecked ->
            kpaValue?.isEnabled = isChecked
        }
    }

    private fun initView() {
        tempValue = binding?.temperatureValue
        humidityValue = binding?.humidityValue
        kpaValue = binding?.kPaValue
        tempSwitch = binding?.tempSwitch
        humiditySwitch = binding?.hum
        kpaSwitch = binding?.isKpa
    }

    companion object {

        @JvmStatic
        fun newInstance() =
            SetParameterFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }
}